<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true"  label-width="70px">
    <!--  <el-form-item label="日期">
        <el-date-picker
          v-model="dateRange"
          type="datetimerange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          style="width: 230px">
        </el-date-picker>
      </el-form-item>-->

      <el-form-item label="技师姓名" prop="nickName">
        <el-input
          v-model="queryParams.nickName"
          placeholder="请输入技师姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="技师编号" prop="userName">
        <el-input
          v-model="queryParams.userName"
          placeholder="请输入技师编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <div style="text-align: right;margin-right:-9px;">
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
       <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-form-item>
      </div>
    </el-form>


    <el-table v-loading="loading" :data="baseinfoList" border>
      <el-table-column type="index" label="序号"  width="55" :index="indexMethod" align="center"/>

      <el-table-column label="技师姓名" align="center" prop="nickName" />
      <el-table-column label="技师编号" align="center" prop="userName" />


      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="xiangqing(scope.row)"
          >详情</el-button>

        </template>
      </el-table-column>
    </el-table>


    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改项目信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="1100px" append-to-body>
      <span>

<el-table v-loading="loading"  max-height="500"  :data="xiangqingdetailsList" border :summary-method="getSummaries" show-summary>
       <el-table-column type="index" label="序号"  width="55" :index="indexMethod" align="center"/>


      <el-table-column label="项目名称" align="center" prop="entryName" />
      <el-table-column label="项目类别" align="center" prop="projectCategory" />
      <el-table-column label="项目代码" align="center" prop="projectCode" />
      <el-table-column label="助记码" align="center" prop="mnemonicCode" />
      <el-table-column label="单位" align="center" prop="unit" />
      <el-table-column label="单价" align="center" prop="unitPrice" />



      <el-table-column label="班次标志" align="center" prop="sailingsSigns" />
      <el-table-column label="录单时间" align="center" prop="recordingTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.recordingTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="数量" align="center" prop="quantity" />

      <el-table-column label="合计金额" align="center" prop="totalAmount" />
 <el-table-column label="提成价" align="center" prop="commissionPrice" />

    </el-table>

        <!--<pagination
            v-show="total>0"
            :total="total"
            :page.sync="queryParams.pageNum"
            :limit.sync="queryParams.pageSize"
            @pagination="getList"
          />-->
      </span>
      <span slot="footer" class="dialog-footer">
    <el-button @click="fanhui()">返回</el-button>

  </span>
    </el-dialog>




  </div>
</template>

<script>
  import { listBaseinfo, getBaseinfo, delBaseinfo, addBaseinfo, updateBaseinfo }from "@/api/module/wyw/jishi";
  import{addDetails,delDetails,getDetails,listDetails,updateDetails} from"@/api/module/wyw/Dryye"

  export default {
    name: "Baseinfo",
    dicts: ['yqg_personnel_status', 'sys_user_sex', 'yqg_post', 'yqg_department'],
    data() {
      return {
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        xiangqingdetailsList:[],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 人员基础信息表格数据
        baseinfoList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        coqueryParams: {
          pageNum: 1,
          pageSize: 10,
          userId: null,
          deptId: null,
          department: null,
          nickName: null,
          userName: null,
          post: null,
          checkoutUserName: null,
          checkoutNickName: null,
          handBrand: null,
          originalHand: null,
          handCategory: null,
          handState: null,
          retentionStatus: null,
          mergeStatus: null,
          openingTime: null,
          drawTime: null,
          mergeHands: null,
          mergeBarBillsId: null,
          leaveTime: null,
          beforeLeave: null,
          beforeBarBillsId: null,
          entryName: null,
          projectCategory: null,
          projectCode: null,
          mnemonicCode: null,
          unit: null,
          unitPrice: null,
          commissionPrice: null,
          together: null,
          handoverStatus: null,
          sailingsSigns: null,
          barBillsId: null,
          recordingTime: null,
          quantity: null,
          totalAmount: null,
          seat: null,
          orderNumber: null,
          paymentMethod: null,
          consumptionStatus: null,
          chargebackTime: null,
          reasonForChargeback: null,
          chargebackProcessorAccount: null,
          chargebackProcessorName: null,
          clockTime: null,
          nextClockTime: null,
          nextClockStatus: null,
          clock: null,
          nextClock: null,
          distanceNextClock: null,
          clockChangeSituation: null,
          timeRemaining: null,
          recordEmployeeNumber: null,
          recorderEmployeeName: null,
          technicianEvaluation: null,
          roomType: null,
          openingHours: null,
          checkOutTime: null,
          checkOutStatus: null,
          inmate: null,
          whetherLeave: null,
          note1: null,
          note2: null,
          note3: null,
          note4: null,
          note5: null,
          note6: null,
          note7: null,
          note8: null,
          note9: null,
          note10: null
        },
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          userId: null,
          deptId: null,
          nickName: null,
          userName: null,
          idNumber: null,
          sex: null,
          phone: null,
          post: 2,
          department: null,
          personnelStatus: null,
          note1: null,
          note2: null,
          note3: null,
          note4: null,
          note5: null
        },
        // 表单参数
        form: {},
        // 表单校验
        rules: {
        }
      };
    },
    created() {
      this.getList();
    },
    methods: {
      fanhui(){
        this.open = false;
        this.reset();
      },

      // 计算表格底部的数据
      getSummaries(param) {
        const {columns, data} = param;
        const sums = [];
        //第一列命名合计
        columns.forEach((column, index) => {
          if (index === 0) {
            sums[index] = '合计';
            return;
          }
          const values = data.map(item => Number(item[column.property]));
          //指定allCompanyNum、allCarNum、allDriverNum不求和，其余列军求和
          if ( column.property == 'totalAmount'|| column.property == 'commissionPrice') {
            sums[index] = values.reduce((prev, curr) => {
              const value = Number(curr);
              if (!isNaN(value)) {
                return prev + curr;
              } else {
                return prev;
              }
            }, 0);
            sums[index];
          } else {
            sums[index] = ''
          }
        });
        return sums
      },



      xiangqing(row) {


        this.loading = true;

        this.coqueryParams.recordEmployeeNumber=row.userName;
        listDetails(this.coqueryParams).then(response => {
          this.xiangqingdetailsList = response.rows;

          this.open = true;
          this.title = "查看详情";
          this.loading = false;
        });
      },



      /** 查询人员基础信息列表 */
      getList() {
        this.loading = true;
        listBaseinfo(this.queryParams).then(response => {
          this.baseinfoList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      indexMethod(index) {
        index = (index + 1) + (this.queryParams.pageNum - 1) * this.queryParams.pageSize
        return index
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      // 表单重置
      reset() {
        this.form = {
          ID: null,
          userId: null,
          deptId: null,
          nickName: null,
          userName: null,
          idNumber: null,
          sex: null,
          phone: null,
          post: null,
          department: null,
          personnelStatus: null,
          note1: null,
          note2: null,
          note3: null,
          note4: null,
          note5: null
        };
        this.resetForm("form");
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.ID)
        this.single = selection.length!==1
        this.multiple = !selection.length
      },
      /** 新增按钮操作 */
      handleAdd() {
        this.reset();
        this.open = true;
        this.title = "添加人员基础信息";
      },
      /** 修改按钮操作 */
      handleUpdate(row) {
        this.reset();
        const ID = row.ID || this.ids
        getBaseinfo(ID).then(response => {
          this.form = response.data;
          this.open = true;
          this.title = "修改人员基础信息";
        });
      },
      /** 提交按钮 */
      submitForm() {
        this.$refs["form"].validate(valid => {
          if (valid) {
            if (this.form.ID != null) {
              updateBaseinfo(this.form).then(response => {
                this.$modal.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              });
            } else {
              addBaseinfo(this.form).then(response => {
                this.$modal.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              });
            }
          }
        });
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        const IDs = row.ID || this.ids;
        this.$modal.confirm('是否确认删除人员基础信息编号为"' + IDs + '"的数据项？').then(function() {
          return delBaseinfo(IDs);
        }).then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        }).catch(() => {});
      },
      /** 导出按钮操作 */
      handleExport() {
        this.download('project/baseinfo/export', {
          ...this.queryParams
        }, `baseinfo_${new Date().getTime()}.xlsx`)
      }
    }
  };
</script>
